package com.lovo.game;

/**
 * 裁判类
 */
public class Judge {

    private Player player;
    private Computer computer;

    public Judge() {
    }

    public Judge(Player player, Computer computer) {
        this.player = player;
        this.computer = computer;
    }

    /**
     * 判断玩家和电脑的输赢
     */
    public void check(){
        int num1 = player.input();
        int num2 = computer.input();
        if (num2 == 0){
            System.out.println("电脑出了石头");
        }else if (num2 == 1){
            System.out.println("电脑出了剪刀");
        }else {
            System.out.println("电脑出了布");
        }

        if (num2 - num1 == 1 || num2 - num1 == -2){
            System.out.println(player.getName() + "赢一局！");
            player.setScore(player.getScore() + 1);
        }else if(num1 - num2 == 0){
            System.out.println("平局");
        }else {
            System.out.println("电脑赢一局！");
            computer.setScore(computer.getScore() + 1);
        }
    }

    /**
     * 总分对比
     */
    public void endCheck(){
        if (player.getScore() > computer.getScore()){
            System.out.println(player.getName() + "获胜！");
        }else if (player.getScore() < computer.getScore()){
            System.out.println("电脑获胜！");
        }else {
            System.out.println("平局");
        }
    }
}
